const mock = require('mockjs')
const bodyparser = require('body-parser')

const {rankList} = mock.mock({
    "rankList": [
        {
            title:"东部",
            "children|15":[{
                name: "@ctitle(2,3)",
                "s|1-50": 1,
                "f|1-50": 1,
                "sl|1-50": 1,
                "sc|1-15": 1,
            }]
        },{
            title:"西部",
            "children|15":[{
                name: "@ctitle(2,3)",
                "s|1-50": 1,
                "f|1-50": 1,
                "sl|1-50": 1,
                "sc|1-15": 1,
            }]
        }
    ]
})
const {newsList} = mock.mock({
    "newsList|100": [
        {
            title:"@ctitle(5,10)",
            "image|0-3":["@image(100x100, @color)"],
            date: new Date().getTime()
        }
    ]
})
const {videoList} = mock.mock({
    "videoList|100": [
        {
            title:"@ctitle(5,10)",
            "image":"@image(100x100, @color)",
            "time|1-100":1,
            "type|1-4":1,
            date: new Date().getTime()
        }
    ]
})
const {scheduleList} = mock.mock({
    "scheduleList|10": [
        {
            data:new Date().getTime(),
            "children|1-15":[{
                "time|1": ['9:00', "10:00","11:00"],
                "type|1": ['总决赛', '季前赛'],
                user1: "@ctitle(2,3)",
                user2: "@ctitle(2,3)",
                "user1Code|1-100": 1,
                "user2Code|1-100": 1,
                "status|1":["已结束","未开赛"]
            }]
        }
    ]
})
module.exports= {
    devServer:{
        before(app) {
            app.use(bodyparser.json())
            // 排名接口
            app.get('/rank', (req,res) => {
                res.send({
                    success:true,
                    data:rankList
                })
            })
            // 新闻接口
            app.get('/news', (req,res) => {
                const {pageIndex,pageSize} = req.query;
                let list = []
                if(pageIndex&&pageSize) {
                    list = newsList.slice((pageIndex-1)*pageSize, pageIndex*pageSize)
                }
                res.send({
                    success:true,
                    data:list
                })
            })
             // 视频接口
             app.get('/vedio', (req,res) => {
                const {pageIndex,pageSize,type} = req.query;
                let list = []
                // 根据type过滤
                if(type) {
                    list = videoList.filter(item => item.type==type)
                }
                // 根据页签页码分页
                if(pageIndex&&pageSize) {
                    list = list.slice((pageIndex-1)*pageSize, pageIndex*pageSize)
                }
                res.send({
                    success:true,
                    data:list
                })
            })
            // 赛程接口
            app.get('/schedule', (req,res) => {
                res.send({
                    success:true,
                    data:scheduleList
                })
            })
        }
    }
}